import { Typography } from 'antd'
import { FC } from 'react'
import { QuestionParagraphProps } from './types'

export const QuestionParagraphDefaultProps: QuestionParagraphProps = {
  text: '一行段落',
  isCenter: false,
}

const Component: FC<QuestionParagraphProps> = props => {
  const { text = '', isCenter = false } = { ...QuestionParagraphDefaultProps, ...props }

  const textList = text.split('\n')

  return (
    <Typography.Paragraph style={{ textAlign: isCenter ? 'center' : 'start', marginBottom: 0 }}>
      {textList.map((text, index) => (
        <span key={index}>
          {index > 0 && <br />}
          {text}
        </span>
      ))}
    </Typography.Paragraph>
  )
}

export default Component
